package com.demo;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class MyLoginAction  extends ActionSupport implements ModelDriven<User>,SessionAware,RequestAware{


	/**
	 * 
	 */
	private static final long serialVersionUID = -8420627935748894215L;
	private User user=new User();
	private Map<String, Object> session;

	@Override
	public String execute() throws Exception {
		System.out.println("in execute method");
		if(user.getUserName().equals("admin") &&  user.getPassword().equals("password")) {
			session.put("user", user);
			return Action.SUCCESS;
		}else {
			session.put("errorMsg", "Invalid user !");
			return Action.INPUT;
		}
	}

	@Override
	public User getModel() {
		return user;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session=session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		
	}
}
